Skip to content

Add LLDB debugger support to swift-test command#9085

Open
plemarquand wants to merge 39 commits intoswiftlang:mainfrom
plemarquand:swift-test-lldb-2
Open

Add LLDB debugger support to swift-test command#9085
plemarquand wants to merge 39 commits intoswiftlang:mainfrom
plemarquand:swift-test-lldb-2

Conversation

@plemarquand
Copy link
Copy Markdown
Contributor

@plemarquand plemarquand commented Sep 2, 2025

Introduces interactive debugging capabilities to swift test via a --debugger flag enabling developers to failing tests directly within LLDB.

This adds debugging parity with swift run --debugger which allows users to debug their executables directly.

When launching lldb this implenentation uses execv() to replace the swift-test process with LLDB. This approach avoids process hierarchy complications and ensures LLDB has full terminal control for interactive debugging features.

When there is only one type of test the debugger creates a single LLDB target configured specifically for that framework. For XCTest, this means targeting the test bundle with xctest as the executable, while Swift Testing targets the test binary directly with appropriate command-line arguments.

When both testing frameworks have tests available we create multiple LLDB targets within a single debugging session. A Python script automatically switches targets as the executable exits, which lets users debug both types of tests spread across two executables in the same session. The Python script also maintains breakpoint persistence across target switches, allowing you to set a breakpoint for either test type no matter the active target.

Note that the CI smoke tests use an old version of LLDB that ships Swift 5.9.2. The --debugger feature relies on the version of LLDB that ships alongside swift-package-manager in the latest toolchain, and so many supporting tests are skipped when running in the smoke test jobs in CI.

Issue: #8129

Comment thread Tests/CommandsTests/TestCommandTests.swift
Comment thread Sources/Commands/SwiftTestCommand.swift
@plemarquand plemarquand force-pushed the swift-test-lldb-2 branch 4 times, most recently from 4d46294 to 1f6e90f Compare September 9, 2025 16:08
Comment thread Tests/CommandsTests/TestCommandTests.swift
Comment thread Tests/CommandsTests/TestCommandTests.swift Outdated
Comment thread Sources/Commands/Utilities/TestingSupport.swift Outdated
Introduces interactive debugging capabilities to `swift test` via a
`--debugger` flag enabling developers to failing tests directly within LLDB.

This adds debugging parity with `swift run --debugger` which allows users
to debug their executables directly.

When launching lldb this implenentation uses `execv()` to replace the
`swift-test` process with LLDB. This approach avoids process hierarchy
complications and ensures LLDB has full terminal control for interactive
debugging features.

When there is only one type of tests the debugger creates a single LLDB
target configured specifically for that framework. For XCTest, this means
targeting the test bundle with xctest as the executable, while Swift Testing
targets the test binary directly with appropriate command-line arguments.

When both testing frameworks have tests available we create multiple LLDB
targets within a single debugging session. A Python script automatically switches
targets as the executable exits, which lets users debug both types of tests
spread across two executables in the same session. The Python script also
maintains breakpoint persistence across target switches, allowing you to set
a breakpoint for either test type no matter the active target.

Finally, we add a `failbreak` command alias that sets breakpoint(s) that break
on test failure, allowing users to automatically stop on failed tests.

Issue: swiftlang#8129
@plemarquand
Copy link
Copy Markdown
Contributor Author

@swift-ci test

@plemarquand
Copy link
Copy Markdown
Contributor Author

@swift-ci test windows

@plemarquand
Copy link
Copy Markdown
Contributor Author

@swift-ci test windows platform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants